import { defineStore } from 'pinia';
import { ref } from 'vue';
import type { User } from '@/types/user';

export const useUserStore = defineStore('user', () => {
  // 用户信息
  const userInfo = ref<User | null>(null);

  // 设置用户信息
  const setUserInfo = (info: User): void => {
    userInfo.value = info;
  };

  // 清除用户信息
  const clearUserInfo = (): void => {
    userInfo.value = null;
  };

  return {
    userInfo,
    setUserInfo,
    clearUserInfo
  };
}, {
  persist: {
    key: 'cloud-library-user',
    storage: localStorage
  }
});
